<template>
  <ux-table-column v-bind="$attrs" :edit-render="!!type" align="center" :fixed="itemName == special ? 'left' : ''" :min-width="itemName == special ? '100' : '150'">
    <template v-slot:edit="scope">
      <template v-if="type == 'number'">
        <el-input class="inputNumber" type="number" v-model.number="scope.row[field]" v-focus @blur="onBlur({ scope, field: value })" />
      </template>
      <template v-else-if="type == 'input'">
        <el-input class="inputNumber" v-model="scope.row[field]" v-focus />
      </template>
    </template>
    <template v-slot="{ row }">{{ showNumber(row[field]) }}</template>
  </ux-table-column>
</template>
<script>
import { countMixins } from "./mixins/countMixins";
export default {
  name: "tableColumn",
  props: {
    field: {
      type: String,
      default: "a"
    },
    type: {
      type: String,
      default: "number"
    },
    value: {
      type: String,
      default: ""
    },
    itemName: {
      type: String,
      default: ""
    }
  },
  mixins: [countMixins],
  data() {
    return {
      special: "gerenxinxi"
    };
  },
  methods: {
    onBlur({ scope, field }) {
      console.log(scope);
      console.group("开始计算", field || this.field, scope);
      this.switchCount(field || this.field, scope.row);
      console.groupEnd();
    },

    /** 处理显示的数字,不影响实际数值 */
    showNumber(number) {
      if (this.itemName != this.special) return number == 0 ? "0.0" : Number(number).toFixed(2);
      else return number;
    }
  }
};
</script>
